/*
    DESCRIPTION HERE
 */

#include "led_effects.h"

int redPin = 12;          // LED connected to digital pin 12
int greenPin = 11;
int bluePin = 10;

int knobPin = 0;        // pin for potentiometer, adjusts sensitivity to light
int photoPin = 2;       // analog input pin for switch
int photoState = 0;
int photoThreshold = 0; // threshold for enabling LEDs

int at = 1;               // start at one
int loopMax = 100;        // # of illuminations until change
int delayTime = 250;      // used for potentiometer data
int trigger = random(1, 6);          // function to run
int lastTrigger = trigger;
int displayed = 0;


// Set to 1 to enable serial debugging, be sure to set baud, too
int debug = 1;
int debug_baud = 9600;

/* END CONFIGURATION */
LED_Effects le(redPin, greenPin, bluePin);

// The setup() method runs once, when the sketch starts
void setup()
{                
  
  randomSeed(analogRead(5));
  Serial.begin(debug_baud);
  
}


void loop()                     
{
  
  photoThreshold = analogRead(knobPin);
  photoState = analogRead(photoPin);
  
  if (photoState < photoThreshold)
  {
    
    // if photocell was just triggered, get new random function
    if (at >= loopMax)
    {
      
      le._reset();
      
      // ensure different trigger each pass
      while (trigger == lastTrigger)
      {
        trigger = random(1, 6);
      }
      
      lastTrigger = trigger;
      at = 0;
    }
    
    switch (trigger)
    {
       
      case 1:
        Serial.println("Trigger 1: downStep");
        le.downStep();
        break;
         
      case 2:
        Serial.println("Trigger 2: downUp");
        le.downUp();
        break;
         
      case 3:
        Serial.println("Trigger 3: upStep");
        le.upStep();
        break;
       
      case 4:
        Serial.println("Trigger 4: allBlink");
        le.allBlink();
        break;
       
      case 5:
        Serial.println("Trigger 5: scroll");
        le.scroll();
        break;
         
      case 6:
        Serial.println("Trigger 6: bounce");
        le.bounce();
        break;
        
      case 7:
        Serial.println("Trigger 7: spring");
        le.spring();
        break;
       
      default:
        trigger = 0;
        break;
       
    }
    
    delay(delayTime);
    at++;
     
  }
  else
  {
    // lights came on, reset everything
    le._reset();
    trigger = 0;
    at = 0;
  }

}
